<HTML>
<HEAD>
<TITLE>[Appendix B] HTML Markup For Applets</TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 14:14:59 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="appa_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Appendix B</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="appc_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<H1 CLASS=appendix><A CLASS="TITLE" NAME="JAWT-APP-B">B. HTML Markup For Applets</A></H1>

<DIV CLASS=htmltoc>

<p>
<b>Contents:</b><br>
The Applet Tag<br>

<p>
</DIV>

<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JAWT-APP-B-SECT-1">B.1 The Applet Tag</A></h2>

<P CLASS=para>
The introduction of Java created the need for additional HTML tags. In 
the alpha release of Java, the HotJava browser used the <TT>&lt;APP&gt;</TT> 
tag to include applets within HTML files. However, <TT>&lt;APP&gt;</TT> 
was unacceptable to the standards committee because it could have an infinite 
number of parameters. It was replaced by the <TT>&lt;APPLET&gt;</TT> 
tag, used in conjunction with the <TT>&lt;PARAM&gt;</TT> 
tag. Apparently, the standards folks did not like the <TT>&lt;APPLET&gt;</TT> 
tag either, so you can expect it to be replaced eventually, although at 
this point, there is no agreement about its successor, and it is highly 
unlikely that any production browser would stop supporting <TT>&lt;APPLET&gt;</TT>. <A NAME="B.APPLET1"></A>

<P CLASS=para>
The syntax of the <TT>&lt;APPLET&gt;</TT> 
tag is shown below; the order of the parameters does not matter: 

<DIV CLASS=programlisting>
<P>
<PRE>
&lt;APPLET
    [ALIGN = alignment]
    [ALT = alternate-text]
    CODE = applet-filename or OBJECT = serialized-applet
    [CODEBASE = applet-directory-url]
    [ARCHIVE = filename.zip/filename.jar]
    HEIGHT = applet-pixel-height
    [HSPACE = horizontal-pixel-margin]
    [MAYSCRIPT = true/false]
    [NAME = applet-name]
    [VSPACE = vertical-pixel-margin]
    WIDTH = applet-pixel-width
&gt;
&lt;PARAM NAME=parameter1 VALUE=value1&gt;
&lt;PARAM NAME=parameter2 VALUE=value2&gt;
&lt;PARAM NAME=parameter3 VALUE=value3&gt;
...
[alternate-html]
&lt;/APPLET&gt;
</PRE>
</DIV>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><TT>&lt;APPLET&gt;</TT> <br>
<DD>

<P CLASS=para>
The <TT>&lt;APPLET&gt;</TT> tag specifies 
where and how to display an applet within the HTML document. If the browser 
does not understand the <TT>&lt;APPLET&gt;</TT> 
and <TT>&lt;PARAM&gt;</TT> tags, it 
displays the <tt CLASS=literal>alternate-html</tt>. (It displays the <tt CLASS=literal>alternate-html</tt> because it 
doesn't understand the surrounding tags and ignores them. There's 
no magic to the <tt CLASS=literal>alternate-html</tt> itself.) If a browser does understand <TT>&lt;APPLET&gt;</TT> 
but cannot run Java (for example, a browser on Windows 3.1) or Java has 
been disabled, the browser displays the <tt CLASS=literal>alternate-html</tt> or the <tt CLASS=literal>alternate-text</tt> 
specified by the optional <tt CLASS=literal>ALT</tt> 
parameter. The <tt CLASS=literal>CODE</tt>, <tt CLASS=literal>WIDTH</tt>, 
and <tt CLASS=literal>HEIGHT</tt> parameters are required. 
Parameters within the <TT>&lt;APPLET&gt;</TT> 
tag are separated by spaces, not by commas. 

<p>
<DT CLASS=varlistentry><TT>&lt;/APPLET&gt;</TT> <br>
<DD>

<P CLASS=para>
Closes the <TT>&lt;APPLET&gt;</TT> tag. 
Anything prior to <TT>&lt;/APPLET&gt;</TT> 
is considered <tt CLASS=literal>alternate-html</tt> if it is not a <TT>&lt;PARAM&gt;</TT> 
tag. The <tt CLASS=literal>alternate-html</tt> is displayed when Java is disabled, when Java cannot 
be run in the current browser, or when the browser does not understand 
the <TT>&lt;APPLET&gt;</TT> tag. </DL>
<P CLASS=para>
The following parameters may appear inside the <TT>&lt;APPLET&gt;</TT> 
tag. 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>ALIGN</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>alignment</tt>, optional. Specifies the applet's alignment on the Web page. Valid values are: <tt CLASS=literal>left</tt>, 
<tt CLASS=literal>right</tt>, <tt CLASS=literal>top</tt>, 
<tt CLASS=literal>texttop</tt>, <tt CLASS=literal>middle</tt>, 
<tt CLASS=literal>absmiddle</tt>, <tt CLASS=literal>baseline</tt>, 
<tt CLASS=literal>bottom</tt>, <tt CLASS=literal>absbottom</tt>. 
Default: <tt CLASS=literal>left</tt>. 
The alignment values have the 
same meanings as they do in the <TT>&lt;IMG&gt;</TT> 
tag. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>ALT</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>alternate-text</tt>, optional. The alternate text is displayed when the browser 
understands the <TT>&lt;APPLET&gt;</TT> 
tag but is incapable of executing applets, either because Java is disabled 
or not supported on the platform. Support of this tag is browser dependent; 
most browsers just display the <tt CLASS=literal>alternate-html</tt> since that is not restricted 
to text. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>ARCHIVE</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>filename.zip/filename.jar</tt>, optional. Points to a comma-separated list of uncompressed ZIP or JAR files 
that contain one or more Java classes. Each file is downloaded 
once to the user's disk and searched for the class named in the <tt CLASS=literal>CODE</tt> 
parameter, and any helper classes required to execute that class. JAR files 
may be signed to grant additional access. (&nbsp;&nbsp;JAR files are Java archives, 
a new archive format defined in Java 1.1. JAR files support features like 
digital signatures and compression. While they are not yet in wide use, 
they should become an important way of distributing sets of Java classes.) 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>CODE</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>applet-filename</tt>. This parameter or the <tt CLASS=literal>OBJECT</tt> 
parameter is required. Name of applet <I CLASS=emphasis>.class</I> 
file. The <I CLASS=emphasis>.class</I> 
extension is not required in the <TT>&lt;APPLET&gt;</TT> 
tag but is required in the class's actual filename. The filename has to be a quoted string only if it includes whitespace. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>CODEBASE</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>applet-directory-url</tt>, optional. Relative or absolute 
URL specifying the directory in which to locate the <I CLASS=emphasis>.class</I> 
file or ZIP archive for the applet. Default: html directory. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>HEIGHT</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>applet-pixel-height</tt>, required. Initial height of applet in pixels. Many 
browsers do not allow applets to change their height. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>HSPACE</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>horizontal-pixel-margin</tt>, optional. Horizontal margin left and right of 
the applet, in pixels. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>MAYSCRIPT</tt> <br>
<DD>

<P CLASS=para>
Required for applets that wish to use LiveConnect and the <tt CLASS=literal>netscape.javascript</tt> 
classes to interact with JavaScript. Set to <tt CLASS=literal>true</tt> 
to communicate with JavaScript. Set to <tt CLASS=literal>false</tt>, 
or omit this parameter to disable communication with JavaScript. Both Java 
and JavaScript must be enabled in the browser. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>NAME</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>applet-name</tt>, optional. Allows simultaneously 
running applets to communicate by this name. Default: the applet's class name. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>OBJECT</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>serialized-applet</tt>. This parameter or the <tt CLASS=literal>CODE</tt> 
parameter is required. Name of applet saved to a file as a serialized object. 
When loaded, <tt CLASS=literal>init()</tt> is not 
called again but <tt CLASS=literal>start()</tt> is. 
Parameters for running the applet are taken from this <TT>&lt;APPLET&gt;</TT> 
tag, not the original. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>VSPACE</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>vertical-pixel-margin</tt>, optional. Vertical margin above and below the applet, 
in pixels. 

<p>
<DT CLASS=varlistentry><tt CLASS=literal>WIDTH</tt> <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>applet-pixel-width</tt>, required. Initial width of applet in pixels. Many browsers 
do not allow applets to change their width. </DL>
<P CLASS=para>
The <TT>&lt;PARAM&gt;</TT> tag may appear 
between the <TT>&lt;APPLET&gt;</TT> 
and <TT>&lt;/APPLET&gt;</TT> 
tags: 

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><TT>&lt;PARAM&gt;</TT> <br>
<DD>

<P CLASS=para>
The <TT>&lt;PARAM&gt;</TT> tag allows 
the HTML author to provide run-time parameters to the applet as a series 
of <tt CLASS=literal>NAME</tt> and <tt CLASS=literal>VALUE</tt> 
pairs. The <tt CLASS=literal>NAME</tt> is case insensitive, 
a <tt CLASS=literal>String</tt>. See <A HREF="ch14_01.htm">Chapter 14, <i>And Then There Were Applets</i></A> 
for a discussion of how to read parameters in an applet. Quotes are required 
around the parameter name or its value if there are any embedded spaces. 
There can be an infinite number of <TT>&lt;PARAM&gt;</TT> 
tags, and they all must appear between <TT>&lt;APPLET&gt;</TT> 
and <TT>&lt;/APPLET&gt;</TT> 

<P CLASS=para>
The special parameter name <tt CLASS=literal>CABBASE</tt> 
is used for sending CAB files with Internet Explorer 3.0. CAB files are 
similar to ZIP files but are compressed into a CABinet file and can store 
audio and image files, in addition to classes. (For a full explanation 
see: <A HREF="http://207.68.137.43/workshop/java/overview.htm">http://207.68.137.43/workshop/java/overview.htm</A>.) 
When <I CLASS=emphasis>.class</I> files 
are placed within a CAB file, they are decompressed at the local end. Here's 
an example: 

<DIV CLASS=programlisting>
<P>
<PRE>
&lt;APPLET CODE="oreilly.class" WIDTH=400 HEIGHT=400&gt;
&lt;PARAM NAME="cabbase" VALUE="ora.cab&gt;
&lt;/APPLET&gt;
</PRE>
</DIV>

<P CLASS=para>
The special parameter name <tt CLASS=literal>ARCHIVES</tt> 
is reserved for sending JAR files. JAR files can also be specified using 
the <tt CLASS=literal>ARCHIVES</tt> parameter to the 
<TT>&lt;APPLET&gt;</TT> tag.[1] 
Here's an example: 

<blockquote class=footnote>
<P CLASS=para>[1] 
For a full explanation see 
<A HREF="http://www.javasoft.com/products/JDK/1.1/docs/guide/jar/index.html">http://www.javasoft.com/products/JDK/1.1/docs/guide/jar/index.html</A>.
</blockquote>
<DIV CLASS=programlisting>
<P>
<PRE>
&lt;APPLET CODE="oreilly.class" WIDTH=400 HEIGHT=400&gt;
&lt;PARAM NAME="archives" VALUE="ora.jar&gt;
&lt;/APPLET&gt;
</PRE>
</DIV>

</DL>
</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="appa_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="appc_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>Resource Bundles</td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Platform-Specific Event Handling</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
